I got this following error while running the python program."AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' in PYTHON".
The below python program is to download image from URL and save it to the pdf file.
CODE:
import requests from reportlab.lib.pagesizes import letter from reportlab.pdfgen import canvas from PIL import Image from io import BytesIO image_url = 'https://tensix.com/wp-content/uploads/2023/11/P6-EPPM-Baseline-Update-Fig-1.jpg' response = requests.get(image_url) if response.status_code == 200: img = Image.open(BytesIO(response.content)) pdf_file = "output.pdf" c = canvas.Canvas(pdf_file, pagesize=letter) max_width = 500 width_percent = max_width / float(img.size[0]) height = int(float(img.size[1]) * float(width_percent)) img = img.resize((max_width, height), Image.Resampling.LANCZOS) temp_img_path = 'temp_image.png' img.save(temp_img_path) c.drawImage(temp_img_path, 50, 700 - height) c.save() print(f"PDF generated with the image: {pdf_file}") else: print("Failed to fetch the image.")
SOLUTION:
ANTIALIAS is worked in old versions. If you are using Pillow 10.0.0 and above You need to use PIL.Image.LANCZOS or PIL.Image.Resampling.LANCZOS.
img = img.resize((max_width, height), Image.Resampling.LANCZOS)
VIDEO GUIDE:
Post your comments / questions
Recent Article
- How to create custom 404 error page in Django?
- Requested setting INSTALLED_APPS, but settings are not configured. You must either define..
- ValueError:All arrays must be of the same length - Python
- Check hostname requires server hostname - SOLVED
- How to restrict access to the page Access only for logged user in Django
- Migration admin.0001_initial is applied before its dependency admin.0001_initial on database default
- Add or change a related_name argument to the definition for 'auth.User.groups' or 'DriverUser.groups'. -Django ERROR
- Addition of two numbers in django python
Related Article